#!/usr/bin/python3
# _*_ coding: utf-8 _*_
#
# Copyright (C) 2024 - 2024 heihieyouheihei, Inc. All Rights Reserved 
#
# @Time    : 2024/9/20 21:34
# @Author  : Yuyun
# @File    : 前序和中序遍历构造二叉树and给出后序遍历.py
# @IDE     : PyCharm

class TreeNode:
    def __init__(self, val=0, left=None, right=None):
        self.val = val
        self.left = left
        self.right = right

class Solution:
    def build_tree(self, midorder:list, preorder:list) -> TreeNode:
        if not preorder:
            return None
        #   前序遍历首值 == 根节点值（中左右）
        root = TreeNode(preorder[0])
        #   找到跟节点位于 中序列表位置
        root_index = midorder.index(root.val)
        #   根据根节点位置，将中序列表拆分为左子树列表和右子树列表（左中右）
        mid_left = midorder[:root_index]
        mid_right = midorder[root_index + 1:]
        #   将前序列表拆分为左子树列表和右子树列表
        pre_left = preorder[1:len(mid_left) + 1]
        pre_right = preorder[len(mid_left) + 1:len(preorder)]
        #   构造根节点左右子树
        root.left = self.build_tree(mid_left, pre_left)
        root.right = self.build_tree(mid_right, pre_right)
        return root

    def postorder_traversal(self, root:TreeNode, res=None) -> list:
        if not res:
            res = []
        if root:
            res = self.postorder_traversal(root.left, res)
            res = self.postorder_traversal(root.right, res)
            res.append(root.val)
        return res
if __name__ == '__main__':
    while True:
        try:
            #   输入字符串，转化为数组
            pre, mid = input().split()
            pre_order = list(pre)
            mid_order = list(mid)
            solution = Solution()
            root = solution.build_tree(mid_order, pre_order)
            result = solution.postorder_traversal(root)
            print(''.join(result))
        except:
            break